//
//  AlertLockTool.m
//  BalanceCar
//
//  Created by 郑信鸿 on 17/6/28.
//  Copyright © 2017年 郑信鸿. All rights reserved.
//

#import "AlertLockTool.h"
#import "ByteTool.h"

@interface AlertLockTool ()

@property(nonatomic, strong)PwSucceedView *succeedView;
@property(nonatomic, strong)TipSuperView *tipSuperView;
@property(nonatomic, strong)PwErrorView *errorView;
@property(nonatomic, strong)PwInputView *inputView;

@end

@implementation AlertLockTool


- (PwErrorView *)errorView{
    
    if (_errorView == nil) {
        
        _errorView = [[PwErrorView alloc] init];
        _errorView.delegate = self;
    }
    
    return _errorView;
}

- (PwSucceedView *)succeedView{
    
    if (_succeedView == nil) {
        
        _succeedView = [[PwSucceedView alloc] init];
    }
    return _succeedView;
}

- (instancetype)initWithTouchBlock:(TouchBtnBlock)touchBlock{
    
    if (self = [super init]) {
        
        self.touchBlock = touchBlock;
        
        [self estblsihSubItems];
        
    }
    return self;
}


- (void)estblsihSubItems{
    
    self.inputView = [[PwInputView alloc] init];
    self.inputView.delegate = self;
    self.tipSuperView = [TipSuperView tipSuperViewWithTipView:self.inputView verticalY:114];
    
}


- (void)showView{
    
    [self.tipSuperView showInView];
    
}

- (void)pwErrorView:(PwErrorView *)view touchWithBtnType:(PasswordBtnType)type{
    
    if (type == PasswordRetry) {
        
        [self.inputView clearPassword];
        [self.tipSuperView replaceTipView:self.inputView];
    }
    if (type == PasswordCallService) {
        //联系客服
        
    }
}

- (void)pwInputView:(PwInputView *)view inputEndWithtext:(NSString *)text{
    
    Byte pwbytes[6] = {};
    [ByteTool hexString:text pwbytes:pwbytes];
    
    [[BaseSendData shareManager] sendConnectPw:pwbytes complete:^(NSInteger code) {
        
        if (self.touchBlock) {
            
            self.touchBlock(code);

        }
        
    }];
    
}

- (void)dealloc{
    
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}


@end
